﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using NUnit.Framework;

namespace ReferenceSwap.Tests
{
    [TestFixture]
    public class ReferenceManagerFixture
    {
        // all run through the same method eventually so we don't need to do these on each method
        // not to mention that these are moderately useful at best
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void VerifyNullProjectCheck()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(null, new List<ProjectReference>(), "", "");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyEmptyAssemblyPathCheck()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(new ProjectData(TestData.ProjectFile), new List<ProjectReference>(), "", "");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyEmptyBuildConfigurationCheck()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(new ProjectData(TestData.ProjectFile), new List<ProjectReference>(), "libs", "");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyNullAssemblyPathCheck()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(new ProjectData(TestData.ProjectFile), new List<ProjectReference>(), null, "");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyNullBuildConfigurationCheck()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(new ProjectData(TestData.ProjectFile), new List<ProjectReference>(), "libs", null);
        }

        [Test]
        [ExpectedException(typeof(DirectoryNotFoundException))]
        public void TestSwapToAssemblyReference_InvalidBuildConfig()
        {
            var target = new ReferenceManager();
            target.SwapToAssemblyReference(new ProjectData(TestData.ProjectFile), new List<ProjectReference>(), "libs", "FakeBuild");
        }

        [Test]
        public void TestSwapToAssemblyReference()
        {
            int expectedAssmReferenceBeforeSwap = 1;
            int expectedProjReferenceBeforeSwap = 3;
            int expectedAssmReferenceAfterSwap = expectedAssmReferenceBeforeSwap+1;
            int expectedProjReferenceAfterSwap = expectedProjReferenceBeforeSwap-1;

            var target = new ReferenceManager();
            var project = new ProjectData(TestData.ProjectFile);
            Assert.Greater(project.ProjectReferences.Count, 0);
            var reference = project.ProjectReferences[0];

            Assert.AreEqual(expectedAssmReferenceBeforeSwap, project.AssemblyReferences.Count);
            Assert.AreEqual(expectedProjReferenceBeforeSwap, project.ProjectReferences.Count);
            
            target.SwapToAssemblyReference(project, new ProjectReference[] { reference }, "libs", "Debug");

            Assert.AreEqual(expectedAssmReferenceAfterSwap, project.AssemblyReferences.Count);
            Assert.AreEqual(expectedProjReferenceAfterSwap, project.ProjectReferences.Count);
        }

    }
}
